package Objects;

import java.util.Objects;

public class test {
    public static void main(String[] args) {
        student s1=new student("张三",12);
        student s2=new student("张三",12);
        boolean result = s1.equals(s2);
        System.out.println(result);

        /*student s3=null;
        student s4=new student("张三",12);
         result = s3.equals(s4);
        System.out.println(result);报错，null不能调用方法*/
        student s3=null;
        student s4=new student("张三",12);
        //Objects.equals会对调用者（s3）先进行非空判断，
        //如果不为null，那就利用调用者（s3）再次调用equals方法
        //此时调用者（s3）是student类型，所以会调用student中重写的equals方法对属性值进行比较
        //若equals没有重写，则比较地址值
        result = Objects.equals(s3, s4);
        System.out.println(result);

        student s5=null;
       result = Objects.isNull(s5);
        System.out.println(result);
        student s6=null;
       result = Objects.nonNull(s6);
        System.out.println(result);
    }
}
